# -*- coding:utf8 -*-

import matplotlib

matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import numpy as np
import mpld3

fig, ax = plt.subplots()

# 生成100个随机数
x, y = np.random.normal(size=(2, 100))

# 绘制散点图
scatter = ax.scatter(x, y)
ax.set_title("Real-time plot")


# 更新图形的数据
def update_plot(data):
    scatter.set_offsets(data)


# 模拟实时数据
for i in range(100):
    x, y = np.random.normal(size=(2, 100))
    data = np.array([x, y]).T
    update_plot(data)
    mpld3.display(fig)
